from importlib import import_module
from typing import Dict, Callable

# 节点类型与执行函数的映射表，通过 config.yaml 动态加载
NODE_EXECUTORS: Dict[str, str] = {}

def register_node_executor(node_type: str, executor_path: str):
    """注册节点类型和对应的执行函数路径"""
    NODE_EXECUTORS[node_type] = executor_path

def get_node_executor(node_type: str) -> Callable:
    """根据节点类型获取执行函数"""
    executor_path = NODE_EXECUTORS.get(node_type)
    if not executor_path:
        raise ValueError(f"Unsupported node type: {node_type}")
    module_name, func_name = executor_path.rsplit(".", 1)
    module = import_module(module_name)
    return getattr(module, func_name)